const mongoose = require('mongoose');

const ImgSchema = new mongoose.Schema({
  name: String,//name
  data: Buffer,
  id: String,//id
});

const AdminSchema = new mongoose.Schema({
  name: { type: String, default: '' },//name
  account: { type: String, default: '' },//account
  password: { type: String, default: '' },//account
  avatar: { type: String, default: '' },//avatar
});

const StudentSchema = new mongoose.Schema({
  name: { type: String, default: '' },//name
  account: { type: String, default: '' },//account
  password: { type: String, default: '' },//account
  avatar: { type: String, default: '' },//avatar
  schoolId: { type: String, default: '' },//所属学校
  classId: { type: String, default: '' },//所属班级
  gender: { type: Boolean, default: null },//性别
})

const TeacherSchema = new mongoose.Schema({
  name: { type: String, default: '' },//name
  account: { type: String, default: '' },//account
  password: { type: String, default: '' },//account
  avatar: { type: String, default: '' },//avatar
  gender: { type: Boolean, default: null },//性别
  schoolId: { type: String, default: '' },//所属学校
  classIds: [{ type: String, default: '' }],//管理班级列表
})

const HomeWorkSchema = new mongoose.Schema({
  name: { type: String, default: '' },// name
  description: { type: String, default: '' },// 说明
  url: { type: String, default: '' },//图片
  teacherId: { type: String, default: '' },// 所属教师
  courseId: { type: String, default: '' },// 所属课程
  published: { type: String, default: '' },// 发布时间
  deadline: { type: String, default: '' },// 截至时间
  scoreIds: [{ type: String, default: '' }],// 成绩表Id
})

const ScoreSchema = new mongoose.Schema({
  student: { type: mongoose.Schema.Types.ObjectId, ref: 'Student' },// 所属学生
  course: { type: mongoose.Schema.Types.ObjectId, ref: 'Course' },// 所属课程
  score: { type: Number, default: 0 },// 成绩
  comment: { type: String, default: '' },// 评语
  submit: { type: String, default: '' },// 提交时间
  status: { type: String, default: '' },// 批改状态
  updated: { type: String, default: '' },// 批改时间
  url: { type: String, default: '' } // 附件图片
});

const CourseSchema = new mongoose.Schema({
  name: { type: String, default: '' }, //  课程名
  classId: { type: String, default: '' }, //  所属班级
  teacherId: { type: String, default: '' }, //  教师
  homeworkList: [{ type: String, default: '' }], //  作业列表
});

const ClassSchema = new mongoose.Schema({
  name: { type: String, default: '' }, //  班级名
  schoolId: { type: String, default: '' }, //  所属学校
  teacherIds: [{ type: String, }], //  教师列表
  studentList: [{ type: String, }], //  学生列表
  courseList: [{ type: String, }], //  课程列表
});

const SchoolSchema = new mongoose.Schema({
  name: { type: String, default: '' }, //  学校名
  address: { type: String, default: '' }, //  学校地址
  zipCode: { type: String, default: '' }, //  邮政编码
  number: { type: String, default: '' }, //  电话
  classList: [{ type: String, default: '' }] //  班级列表
});

module.exports = {
  Student: mongoose.model('Student', StudentSchema),
  Teacher: mongoose.model('Teacher', TeacherSchema),
  HomeWork: mongoose.model('HomeWork', HomeWorkSchema),
  Course: mongoose.model('Course', CourseSchema),
  Claxx: mongoose.model('Class', ClassSchema),
  School: mongoose.model('School', SchoolSchema),
  Admin: mongoose.model('Admin', AdminSchema),
  Score: mongoose.model('Score', ScoreSchema),
  ImgSchema: mongoose.model('Img', ImgSchema),
}